"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NavItemMiniLayout = NavItemMiniLayout;

var _react = _interopRequireWildcard(require("react"));

var _configContext = require("../../../../extends/configContext");

var _classnames = _interopRequireDefault(require("classnames"));

var _sideNavContext = require("../../sideNavContext");

var _components = require("@tarojs/components");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function NavItemMiniLayout(_ref) {
  var _classNames, _classNames2;

  var className = _ref.className,
      style = _ref.style,
      index = _ref.index,
      children = _ref.children;

  var _useContext = (0, _react.useContext)(_configContext.ConfigContext),
      clsPrefix = _useContext.clsPrefix;

  var _useContext2 = (0, _react.useContext)(_sideNavContext.SideNavItemContext),
      defaultActiveIndex = _useContext2.defaultActiveIndex,
      activeIndex = _useContext2.activeIndex,
      activeClassName = _useContext2.activeClassName,
      activeStyle = _useContext2.activeStyle,
      _onClick = _useContext2.onClick,
      direction = _useContext2.direction,
      connect = _useContext2.connect;

  var current = activeIndex || defaultActiveIndex; // 防止出现activeIndex=0时，current不等于activeIndex的情况

  if (activeIndex === 0) {
    current = activeIndex;
  }

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)(className, "".concat(clsPrefix, "-side-nav-item"), (_classNames = {}, _defineProperty(_classNames, activeClassName, index === current), _defineProperty(_classNames, "".concat(clsPrefix, "-side-nav-item--vertical"), direction === 'vertical'), _defineProperty(_classNames, "".concat(clsPrefix, "-side-nav-item--horizontal"), direction === 'horizontal'), _classNames)),
    style: index === current ? _objectSpread(_objectSpread({}, style), activeStyle) : style,
    onClick: function onClick(e) {
      _onClick(e, index);
    }
  }, // 导航栏前的小图标
  index === current ? /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-side-nav-item__circleBox"))
  }, /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-side-nav-item__innerRing"))
  })) : /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)("".concat(clsPrefix, "-side-nav-item__circle"))
  }), children), connect ? {
    connect: connect
  } : /*#__PURE__*/_react.default.createElement(_components.View, {
    className: (0, _classnames.default)((_classNames2 = {}, _defineProperty(_classNames2, "".concat(clsPrefix, "-side-nav-item__connect--vertical"), direction === 'vertical'), _defineProperty(_classNames2, "".concat(clsPrefix, "-side-nav-item__connect--horizontal"), direction === 'horizontal'), _classNames2))
  }));
}